<template>

  <div>
    <slotname>
      <div slot="pr" class="prbox">
        <img src="../../assets/img/zc.jpg">
      </div>
      <div slot="main" class="mainbox">
        <el-form :model="nuser"  status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm"
          action="http://localhost:8081/json/SpringMVC_18001010209/zuceuser.do" method="post" onsubmit="togo">
          <el-form-item>
            <h1>欢迎注册</h1>
          </el-form-item>
          <el-form-item label="用户名" prop="uname">
            <el-input  v-model="nuser.uname" name="uname" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="upassword">
            <el-input type="password" name="upassword" v-model="nuser.upassword" autocomplete="off" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item label="重复密码" prop="upassword2">
            <el-input type="password" name="upassword2" v-model="nuser.upassword2" autocomplete="off" placeholder="请重复输入密码"></el-input>
          </el-form-item>
          <el-form-item label="昵称" prop="uickname">
            <el-input  name="uickname" v-model="nuser.uickname" autocomplete="off" placeholder="请输入昵称"></el-input>
          </el-form-item>
          <el-form-item label="个人简介"  prop="uintroduce">
            <el-input  name="uintroduce" v-model="nuser.uintroduce" autocomplete="off" type="textarea" :rows="2"  placeholder="请输入个人简介" maxlength="100"></el-input>
          </el-form-item>
          <span style="color:red">{{msg}}</span>
          <el-form-item>
            <el-button onclick="nuser.reset();"> 重置</el-button>

            <router-link to="login">
              <el-button>注册</el-button><br>
            </router-link>
            <span> 已有账号？请先<router-link to="/login">登录</router-link></span>
          </el-form-item>
        </el-form>
      </div>
    </slotname>
  </div>
</template>

<script>
  import slotname from "./slot"
  export default {
    name: 'zuce',
    data() {
      var validatePass2 = (rule, value, callback) => {
         if (value !== this.nuser.upassword) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
           
        nuser:{
            uname:"",
            upassword:"",
            upassword2:"", 
            uickname:"",
            uintroduce:"",

        },
        rules:{
          uname: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 3, message: '长度最小 3 个字符', trigger: 'blur' },
            { pattern:/^[a-zA-Z][a-zA-Z0-9]*$/, message:'请以字母开头' , trigger: 'blur' }
          ],
           upassword: [
            { required: true, message: '请输入密码', trigger: 'blur' },
             { min: 3, message: '长度最小 6 个字符', trigger: 'blur' },
          ],
          upassword2: [
            { required: true, message: '请重复输入密码', trigger: 'blur' },
            { validator: validatePass2, trigger: 'blur' }
          ],
          uickname: [
            { required: true, message: '请输入昵称', trigger: 'blur' },
         ],
          uintroduce: [
            { required: true, message: '请输入描述', trigger: 'blur' },
          ]
        },
      
       msg:"",
       flag:"",
      };
    },
    methods: {
    login(){
      this.$axios.post('zuceuser.do?uname='+this.nuser.uname+'&upassword='+this.nuser.upassword
                              +'&uickname='+this.nuser.uickname+'&uintroduce='+this.nuser.uintroduce).then(
        response=>{
          this.flag=response.data;
          if(this.flag>0){
              this.$router.push({
                  path:"/login",
              })
          }else{
            this.mag="注册失败"
          }
        }
      )
    }
      
    },
    components: {
      slotname
    },
  }
</script>

<style>
  .prbox img {
  width: 100%;
    height: 800px;
  border-radius: 25px;
  }

  .mainbox {
    margin: 200px auto;
    width: 300px;
  }
</style>